package com.entrogy.controller;

import com.entrogy.service.StudentService;
import com.entrogy.utils.ApiReturnUtil;
import com.entrogy.utils.StrUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(description = "对学生的相关管制(通行权限,返校统计,考勤流水,考勤查询,返校统计)")
@RestController
@RequestMapping(value = "studentcontrol")
public class StudentControlController {

    @Autowired
    private StudentService studentService;

    @ApiOperation(value = "德育处设置所有学生的通行时间段(更新学生的控权时间 中午，下午，晚上 只有德育处的老师有权限)")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "需要修改的所有学生允许的时间段",name = "allowTimes",dataType = "String",paramType = "query",required = true),
            @ApiImplicitParam(value = "需要修改的所有学生ID",name = "studentIDs",dataType = "String",paramType = "query",required = true)
    })
    @RequestMapping(value = "/updatecontrol",method = RequestMethod.POST)
//    @RequiresPermissions("student_control:update")
    public Map<String,Object> updateStudentControl(String allowTimes,String studentIDs) {
        int code = studentService.updateStudentControl(studentIDs, allowTimes);
        if(code == 0){
            return ApiReturnUtil.error("对不起,网络异常哟");
        }else if(code == 2){
            return ApiReturnUtil.error("您没有做任何改动哟");
        }
        return ApiReturnUtil.success("设置成功","");
    }

    @ApiOperation(value = "家长或班主任更新学生的离校状态")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户ID",name = "uid",dataType = "String",paramType = "query",required = true),
            @ApiImplicitParam(value = "需要修改的所有学生ID",name = "studentIDs",dataType = "String",paramType = "query",required = true),
            @ApiImplicitParam(value = "需要修改的所有学生离校状态",name = "leaveTypes",dataType = "String",paramType = "query",required = true)
    })
    @RequestMapping(value = "/studentsetup",method = RequestMethod.POST)
    public Map<String,Object> updateStudentSetUp(String uid,String studentIDs,String leaveTypes) {
        int code = studentService.updateStudentSetUp(uid,studentIDs, leaveTypes);
        if(code == 0){
            return ApiReturnUtil.error("对不起,网络异常哟");
        }
        return ApiReturnUtil.success("设置成功","");
    }



}
